package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Message;
import cn.wolfcode.crm.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("message")
@Controller
public class MessageController {
    // @Autowired
    //private IMemberMapper memberMapper;
    @Autowired
    private IMessageService messageService;

    @RequestMapping("")
    public String index() {
        return "message/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public List<Map<String, Object>> list( ) {
        //List<Message> list = messageService.list();
        List<Map<String, Object>> list1 = new ArrayList<>();
        List<Message> list = messageService.list();
        for (Message message : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("memberName", message.getMember().getMemberName());
            map.put("tel", message.getMember().getTel());
            map.put("content", message.getContent());
            map.put("sendDate", message.getSendDate());
            list1.add(map);
        }
        return list1;
    }
    @RequestMapping("queryCheckMessage")
    @ResponseBody
    public List<Message> queryCheckMessage(){
        return messageService.queryCheckMessage();
    }
}